/* 使用mock模拟分类相关的接口 */
import Mock from 'mockjs'
import { topCategory } from '@/api/constants'

const images = [
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(1).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(2).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(3).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(4).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(5).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(6).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(7).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(8).png'
]
export function getTopCategory() {
  const result = []
  topCategory.forEach(item => {
    const obj = Mock.mock({
      name: item,
      id: '@id'
    })
    result.push(obj)
    // obj缺少children属性
    const children = []
    obj.children = children
    images.forEach(image => {
      const sub = Mock.mock({
        id: '@id',
        name: '@cname(2,3)',
        picture: image
      })
      children.push(sub)
    })
  })
  return {
    msg: '获取成功',
    result: result
  }
}
